package com.example.dormitory.service;


import com.example.dormitory.entity.*;
import com.example.dormitory.mapper.*;
import com.github.pagehelper.PageHelper;
import com.github.pagehelper.PageInfo;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;
import org.springframework.util.StringUtils;

@Service
public class ChooseDormitoryService {

    @Autowired
    private ChooseDormitoryMapper chooseDormitoryMapper;

    public int create(ChooseDormitory chooseDormitory) {
        return chooseDormitoryMapper.create(chooseDormitory);
    }

    public int delete(String ids) {
        String[] arr = ids.split(",");
        int row = 0;
        for (String s : arr) {
            if(!StringUtils.isEmpty(s)){
                chooseDormitoryMapper.delete(Integer.parseInt(s));
            row++;
            }
        }
        return row;
    }

    public int delete(Integer id) {
        return chooseDormitoryMapper.delete(id);
    }

    public int update(ChooseDormitory chooseDormitory) {
        return chooseDormitoryMapper.update(chooseDormitory);
    }

    public int updateSelective(ChooseDormitory chooseDormitory) {
        return chooseDormitoryMapper.updateSelective(chooseDormitory);
    }

    public PageInfo<ChooseDormitory> query(ChooseDormitory chooseDormitory) {
        if(chooseDormitory != null && chooseDormitory.getPage() != null){
            PageHelper.startPage(chooseDormitory.getPage(),chooseDormitory.getLimit());
        }
        return new PageInfo<ChooseDormitory>(chooseDormitoryMapper.query(chooseDormitory));
    }

    public ChooseDormitory detail(Integer id) {
        return chooseDormitoryMapper.detail(id);
    }

    public int count(ChooseDormitory chooseDormitory) {
        return chooseDormitoryMapper.count(chooseDormitory);
    }
}
